---@diagnostic disable: lowercase-global, undefined-global, trailing-space

---@type data_componentaction[]
local data = {
    -- 右键手术刀
    {
        id = 'ACTION_KKD_SCALPEL',
        str = STRINGS.MOD_KUKUDE.ACTIONS.ACTION_KKD_SCALPEL,
        fn = function (act)
            if act.doer and act.doer:IsValid() and act.invobject and act.invobject:IsValid() then
                return (function (doer,obj)
                    local fleshsack = doer.components.inventory:GetEquippedItem(EQUIPSLOTS.KKD_FLESH)
                    if fleshsack ~= nil and fleshsack.components.container ~= nil then
                        if fleshsack.components.container:IsOpen() then
                            fleshsack.components.container:Close(doer)
                            fleshsack._opened_by_scalpel = false
                        else
                            fleshsack.components.container:Open(doer)
                            fleshsack._opened_by_scalpel = true
                        end
                    end
                    return true
                end)(act.doer,act.invobject)
            end
            return false
        end,
        state = "kukude_scalpel",
        actiondata = {
            priority = 10,
            mount_valid = false,
        },
        type = 'INVENTORY',
        component = 'inventoryitem',
        testfn = function (inst, doer, actions, right)
            -- print('这里写动作出现条件')
            return doer:HasTag("player") and inst.prefab == 'kkd_scalpel' 
        end
    },
    -- 植入物 io_greenfinger 获得随地种植及快速对话能力
    --[[{
        id = 'ACTION_KKD_IO_QUICK_PLANT',
        str = STRINGS.MOD_KUKUDE.ACTIONS.ACTION_KKD_IO_QUICK_PLANT,
        fn = function (act)
            if act.doer and act.doer:IsValid() and act.invobject and act.invobject:IsValid() then
                return (function (doer,obj,pos,rt)
                    local container = doer.components.inventory or doer.components.container
                    local _obj = container ~= nil and container:RemoveItem(obj) or nil
                    if _obj ~= nil then
                        if _obj.components.deployable:Deploy(pos, doer, rt) then
                            return true
                        else
                            container:GiveItem(_obj)
                        end
                    end
                    return false
                end)(act.doer,act.invobject,act:GetActionPoint(),act.rotation)
            end
            return false
        end,
        state = 'doshortaction',
        actiondata = {
            mount_valid = false,
            priority = 10,
        },
        type = 'POINT',
        component = 'farmplantable',
        testfn = function (inst, doer, pos, actions, right)
            return right and doer:HasTag("player") and doer:HasTag('io_greenfinger_ability') and (inst.prefab == "seeds" or string.match(inst.prefab, "_seeds")) and
                inst.replica.inventoryitem:CanDeploy(pos, nil, doer, (doer.components.playercontroller ~= nil and doer.components.playercontroller.deployplacer ~= nil) and doer.components.playercontroller.deployplacer.Transform:GetRotation() or 0)
        end
    },]]
    {
        id = 'ACTION_KKD_IO_QUICK_TEND',
        str = STRINGS.MOD_KUKUDE.ACTIONS.ACTION_KKD_IO_QUICK_TEND,
        fn = function (act)
            if act.doer and act.doer:IsValid() and act.target and act.target:IsValid() then
                return (function (doer,tar)
                    if tar.components.farmplanttendable then
                        tar.components.farmplanttendable:TendTo(doer)
                        if doer.components.talker ~= nil then
                            doer.sg:AddStateTag("idle") -- allow talker state to take over
                            doer.components.talker:Say(GetString(doer, "ANNOUNCE_TALK_TO_PLANTS"))
                        end
                        return true
                    end
                    return false
                end)(act.doer,act.target)
            end
            return false
        end,
        state = 'doshortaction',
        actiondata = {
            mount_valid = false,
            priority = 10,
        },
        type = 'SCENE',
        component = "farmplanttendable",
        testfn = function (inst, doer, actions, right)
            return doer:HasTag("kukude") and doer:HasTag('io_greenfinger_ability') and inst:HasTag("tendable_farmplant") -- 这个tag只有需要照顾的植物才有
        end
    },
    {
        id = 'ACTION_KKD_DISSECT_BY_SCALPEL',
        str = STRINGS.MOD_KUKUDE.ACTIONS.ACTION_KKD_DISSECT_BY_SCALPEL,
        fn = function (act)
            if act.doer and act.doer:IsValid() and act.target and act.target:IsValid() then
                return (function (doer,tar)
                    if doer.components.kkd_dissect then 
                        doer.components.kkd_dissect:OnDissect(tar)
                    end
                    return true
                end)(act.doer,act.target)
            end
            return false
        end,
        state = 'dolongaction',
        actiondata = {
            mount_valid = false,
            priority = 10,
        },
        type = 'USEITEM',
        component = "inventoryitem",
        testfn = function (inst, doer, target, actions, right)
            return doer:HasTag("kukude") and inst.prefab == "kkd_scalpel" and target:HasTag("kkd_corpse")
        end
    }
}


---@type data_componentaction_change[]
local change = {}

return data,change